package com.xieman.anti.replay.utils;


import com.xieman.anti.replay.exception.ArgumentException;

import java.util.Collection;
import java.util.Objects;

public class Assert {

    private Assert() {}

    public static void isNull(Object obj, String message) {
        if (!Objects.isNull(obj)) {
            throw new ArgumentException(message);
        }
    }

    public static void notNull(Object obj, String message) {
        if (Objects.isNull(obj)) {
            throw new ArgumentException(message);
        }
    }

    public static void isEmpty(Collection collection, String message) {
        if (collection != null && !collection.isEmpty()) {
            throw new ArgumentException(message);
        }
    }

    public static void notEmpty(Collection collection, String message) {
        if (collection == null || collection.isEmpty()) {
            throw new ArgumentException(message);
        }
    }

    public static void isEmpty(String str, String message) {
        if (StringUtils.isNotEmpty(str)) {
            throw new ArgumentException(message);
        }
    }

    public static void notEmpty(String str, String message) {
        if (StringUtils.isEmpty(str)) {
            throw new ArgumentException(message);
        }
    }

    public static void notBlank(String str, String message) {
        if (StringUtils.isBlank(str)) {
            throw new ArgumentException(message);
        }
    }

    public static void isTrue(boolean b, String message) {
        if (!b) {
            throw new ArgumentException(message);
        }
    }

    public static void isFalse(boolean b, String message) {
        if (b) {
            throw new ArgumentException(message);
        }
    }
}
